<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp_lib/init.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>版本列表</title>
<jsp:include page="/WEB-INF/jsp/common/common.jsp" />
<jsp:include page="/WEB-INF/jsp_lib/extjs.jsp" />

<script type="text/javascript">
	var dataStore;

	Ext.onReady(function() {

		dataStore = Ext.create('Ext.data.Store', {
			fields : [ 'app', 'version', 'note', 'kid' ],
			remoteSort : false,
			autoLoad : true,
			pageSize : 20,
			proxy : {
				type : "ajax",
				url : "${path}/cp/version/list_data.htm",
				reader : {
					type : 'json',
					rootProperty : 'list',
					totalProperty : 'page.rowTotal'
				}
			}
		}); //#dataStore

		var listGridPanel = Ext.create('Ext.grid.Panel', {
			title : '版本列表',
			columnLines : true,
			rowLines : true,
			height:300,
			collapsible : false,
			plugins : [ Ext.create('Ext.grid.plugin.CellEditing', {
				clicksToEdit : 1
			}) ],
			dockedItems : [ {
				xtype : 'pagingtoolbar',
				store : dataStore, // same store GridPanel is using
				dock : 'bottom',
				displayInfo : true
			} ],
			store : dataStore,
			columns : [ {
				text : '版本',
				dataIndex : 'app',
			}, {
				text : '版本号',
				dataIndex : 'version',
				editor : {
					xtype : 'textfield',
					regex : /^[0-9]+(.[0-9]+)?$/,
					regexText : "输入格式错误",
					maxLength : 20,
					allowBlank : false,
				}
			}, {
				text : '备注',
				dataIndex : 'note',
				flex : 1,
				editor : {
					xtype : 'textareafield',
					allowBlank : true,
				}
			} ]
		}); //#listGridPanel

		listGridPanel.on('edit', function(editor, e) {
			var val = e.value, old_val = e.originalValue, msg = e.field, kid = e.record.get("kid");
			if (val != old_val) {
				Ext.Msg.alert("信息", "确认修改吗？！", function() {
					Ext.Ajax.request({
						url : "${path}/cp/version/edit.htm",
						method : "POST",
						params : {
							val : val,
							msg : msg,
							kid : kid
						},
						success : function(response) {
							dataStore.reload();
						},
						failure : function(response) {
							Ext.Msg.alert("警告", "数据更新失败，请稍后再试！");
						}
					});
				});
			}
		});

		listGridPanel.render(Ext.getBody());

	});
</script>
</head>
<body>

</body>
</html>